package com.gyf.base.ui.activity

import android.os.Bundle
import com.gyf.base.common.BaseApplication
import com.gyf.base.injection.component.ActivityComponent
import com.gyf.base.injection.component.DaggerActivityComponent
import com.gyf.base.injection.module.ActivityModule
import com.gyf.base.injection.module.LifecyclerProviderModule
import com.gyf.base.presenter.BasePresenter
import com.gyf.base.presenter.view.BaseView
import com.gyf.base.widget.ProgressLoading
import org.jetbrains.anko.support.v4.toast
import org.jetbrains.anko.toast
import javax.inject.Inject

open abstract class BaseMvpActivity<T : BasePresenter<*>> : BaseActivity(), BaseView {
   private lateinit var mLoadingDialog: ProgressLoading;
    override fun showLoading() {
        mLoadingDialog.showLoading();
    }

    override fun hideLoading() {
        mLoadingDialog.hideLoading();
    }

    override fun onError(text:String) {
        toast(text);
    }

    abstract fun injectComponent();

    @Inject
    lateinit var mPresenter: T

    lateinit var activityComponent: ActivityComponent

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        activityComponent = DaggerActivityComponent.builder().appComponent((application as BaseApplication).appComponent)
                .activityModule(ActivityModule(this))
                .lifecyclerProviderModule(LifecyclerProviderModule(this))
                .build();
        injectComponent();
        mLoadingDialog = ProgressLoading.create(this);
    }
}